﻿using Infrastructure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC4.Controllers
{
    public class QrCodeController : Controller
    {
        //
        // GET: /QrCode/

        public void Index(string id, bool isUrl = false, int width = 200, int height = 200)
        {
            if (string.IsNullOrWhiteSpace(id)) { return; }
            using (MemoryStream ms = new MemoryStream())
            {
                QrCreater creater = new QrCreater();
                System.Drawing.Image imgCode = creater.CreateImage(id, isUrl, width, height);
                imgCode.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                Response.ContentType = "image/png";
                Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length);
            }
        }

    }
}
